<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<%
	String type = request.getParameter("type") == null ? "" : request.getParameter("type");
	String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
	String dept_id = request.getParameter("dept_id") == null ? "" : request.getParameter("dept_id");
	String dept_name = request.getParameter("dept_name") == null ? "" : request.getParameter("dept_name");
	String gd_code = request.getParameter("gd_code") == null ? "" : request.getParameter("gd_code");
	String gd_name = request.getParameter("gd_name") == null ? "" : request.getParameter("gd_name");
%>
<html>
	<head>
		<title>补采购单</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValueTwo").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
			});
			$("#table").datagrid({
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/gd/listPageGDSupplierApplyForPurchase?type=<%=type%>&gd_id=<%=gd_id%>',
				fitColumns:true,
				rownumbers:true,
				idField:'id',
				frozenColumns:[[
				    {field:'gd_id',hidden:true},
				    {field:'supplier_id',hidden:true}
				]],
				columns:[[
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:150,align:'center'},
					{title:'厂家',field:'supplier',width:150,align:'center'},
					{title:'当前状态',field:'edit',width:100,align:'center',formatter:function(value,row,rowIndex){
						var purchase_id = '0';
						$.ajax({
							type:'POST',
							async:false,
							url:'<%=contextPath %>/springMVC/gd/getSupplierPurchase?type='+row.type+'&gd_id='+row.gd_id+'&supplier_id='+row.supplier_id,
							success:function(rtJson){
								purchase_id = rtJson;
							}
						});
						if(purchase_id == '0'){
							return "还没补订单";
						}else{
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看订货单' onclick=\"javascript:showPurchase('"+purchase_id+"');\"/>";
						}
					}}
				]],
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var supplier_id = row.supplier_id;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					 ddv.datagrid({
						title:'明细',
						url:'<%=contextPath %>/springMVC/gd/listGDSupplierApplyForPurchaseDetail?type=<%=type%>&gd_id=<%=gd_id%>&supplier_id='+supplier_id+'&yet=0',
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						rownumbers:true,
						columns:[[
							{title:'产品编号',field:'code',width:100,align:'center'},
							{title:'产品名称',field:'name',width:200,align:'center'},
							{title:'规格/型号',field:'format_type',width:200,align:'center'},
							{title:'单位',field:'unit_name',width:100,align:'center'},
							{title:'数量',field:'num',width:100,align:'center'}
						]],
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function showPurchase(purchase_id){
			openDialogResize("<%=contextPath %>/springViews/warehouse/addOrEditSupplierPurchase.jsp?isShow=1&purchase_id="+purchase_id,1000, 800);
		}
		function doSearch()
		{
			var searchValueTwo = $('#searchValueTwo').val();
			$('#table').datagrid('load',{
				searchValueTwo:searchValueTwo
				
			});
		}
	</script>
	<body>
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div align="right">
				内容摘要：<input id="searchValueTwo" name="searchValueTwo" style="width:150px" title="内容摘要"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>